<template>
	<view class="redEnvelope">
		<view class="tabBox">
			<u-subsection :list="tabList" :current="current" active-color="#fe0000" @change="sectionChange">
			</u-subsection>
		</view>
		<view class="listBox" :class="current == 0 ? '' : 'invalidation'">
			<block v-for="(item, index) in this_data_list" :key="index">
				<view class="item">
					<view class="left">
						<view class="amount">{{item.q_amount}}<text class="text">元</text></view>
					</view>
					<view class="center">
						<view class="time">{{item.time}}</view>
					</view>
					<button @click="go_home" v-if="item.q_status==0" type="default" size="mini" class="btn">去拼团</button>
					<button v-if="item.q_status==1" type="default" size="mini" class="btn">已释放</button>
				</view>
			</block>
		</view>
		<view class="noContent" v-if="this_data_list.length == 0">
			<image class="noContentImage" mode="widthFix" src="/static/noLive.png"></image>
		</view>
	</view>
</template>

<script>
	var util = require('../../common/util.js');
	export default {
		data() {
			return {
				tabList: [
					{
						name: '待释放'
					}, 
					{
						name: '已释放'
					}
				],
				current: 0,
				this_data_list:[],
				this_select_type:0,
				this_pagesize:1,
				this_pagenum:20,
				isMore:true
			}
		},
		onLoad() {
			this.get_index_data();
		},
		methods: {
			sectionChange(index) {
				this.current = index;
				this.this_select_type = index;
				this.this_pagesize = 1;
				this.isMore = true;
				this.this_data_list = [];
				this.get_index_data();
			},
			get_index_data:function(){
				let _this = this;
				const param = {};
				param.pagesize = _this.this_pagesize;
				param.pagenum = _this.this_pagenum;
				param.select_type = _this.this_select_type;
				util.requestPost('api.php/UserCoupon/getUserCouponList',param,function(res) {
						if(res.data.this_data_list.length >= _this.this_pagenum){
							_this.this_pagesize = _this.this_pagesize + 1;
							_this.isMore = true;
						}else{
							_this.isMore = false;
						}
						if(_this.this_data_list.length > 0){
							_this.this_data_list = _this.this_data_list.concat(res.data.this_data_list);
						}else{
							_this.this_data_list = res.data.this_data_list;
						}
					}
				);
			},
			onReachBottom:function(){
				let _this = this;
				if(_this.isMore == true) _this.get_index_data();
			},
			go_home:function(){
				uni.switchTab({
					url:"/pages/index/index"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.redEnvelope {
	min-height: 100%;
	background-color: var(--bgColor);

	.tabBox {
		padding: 12rpx 24rpx;
		background-color: #FFFFFF;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
	}
	.listBox {
		padding: 114rpx 24rpx 24rpx;
		.item {
			border-radius: 12rpx;
			background: var(--btnBgColor);
			padding: 24rpx 24rpx 24rpx 12rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20rpx;
			position: relative;
			overflow: hidden;
			&:last-of-type {
				margin-bottom: 0;
			}
			.left {
				width: 280rpx;
				text-align: center;
				margin-right: 12rpx;
				.amount {
					font-size: 48rpx;
					font-weight: bold;
					color: #FFFFFF;
					.text {
						font-size: 24rpx;
					}
				}
			}
			.center {
				flex: 1;
				.time {
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 8rpx;
				}
			}
			.btn {
				font-size: 24rpx;
				color: var(--primaryColor);
				border-radius: 80rpx;
				background-color: #FFFFFF;
				margin: 0 0 0 12rpx;
				&::after {
					border: none;
				}
			}
			.img {
				width: 120rpx;
				position: absolute;
				right: -16rpx;
				bottom: -16rpx;
			}
		}
		&.invalidation {
			.item {
				background: #FFFFFF;
				.left {
					.amount {
						color: #999999;
					}
				}
				.center {
					.time {
						color: #999999;
					}
				}
			}
		}
	}
}
</style>
